/*---------------------------------------------------------------------------*\
  =========                 |
  \\      /  F ield         | OpenFOAM: The Open Source CFD Toolbox
   \\    /   O peration     |
    \\  /    A nd           | www.openfoam.com
     \\/     M anipulation  |
-------------------------------------------------------------------------------
    Copyright (C) 2025 AUTHOR,AFFILIATION
-------------------------------------------------------------------------------
License
    This file is part of OpenFOAM.

    OpenFOAM is free software: you can redistribute it and/or modify it
    under the terms of the GNU General Public License as published by
    the Free Software Foundation, either version 3 of the License, or
    (at your option) any later version.

    OpenFOAM is distributed in the hope that it will be useful, but WITHOUT
    ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
    FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
    for more details.

    You should have received a copy of the GNU General Public License
    along with OpenFOAM.  If not, see <http://www.gnu.org/licenses/>.

Application
    roughness

Description

\*---------------------------------------------------------------------------*/

#include "fvCFD.H"
// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
#include "findMinMaxBox.H"
#include <random>

int main(int argc, char *argv[])
{
    #include "setRootCase.H"
    #include "createTime.H"
    #include "createMesh.H" 
    
    // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //

    IOdictionary addRoughnessDict
    (
        IOobject
        (
            "addRoughnessDict",
            runTime.constant(),
            mesh,
            IOobject::MUST_READ,
            IOobject::NO_WRITE
        )
    );

    const word bedType = addRoughnessDict.lookupOrDefault<word>("bedType", "plane"); 
    const direction streamDir(addRoughnessDict.get<label>("streamwise"));
    const direction spanDir(addRoughnessDict.get<label>("spanwise"));
    const word      bedPatchName(addRoughnessDict.get<word>("bedpatchname"));
    const scalar    minValue(addRoughnessDict.get<scalar>("minValue")); // 用于随机数生成，最小值
    const scalar    maxValue(addRoughnessDict.get<scalar>("maxValue")); // 用于随机数生成，最大值

    vector refDir(Zero);
    refDir[streamDir] = 1.0; // 读取字典，判断流向方向

    Info << "Stream direction is: " << streamDir << nl
         << "Span direction is:   " << spanDir << nl
         << "Bed's ref plane is : ("<<streamDir<<","<<spanDir<<")" << nl
         << "Bed patch name is:   " << bedPatchName 
         << endl;

    OFstream outputFile("bedFaceAngles.csv");
    OFstream boxFile("system/boxes.txt");  
    outputFile << "BedPatchName,FaceIndex,Angle(deg)" << endl;
    
    if(bedType == "plane")
    {
        Info << "Bed type is plane" << nl;
        #include "plane.C"
    }else if (bedType == "slope")
    {
        Info << "Bed type is slope" << nl;
        #include "slope.C"
    }else
    {
        FatalError
        << "Unknown bed type: " << bedType
        << exit(FatalError);
    }

    Info<< "\nAngles of bed patch written to bedFaceAngles.csv" << nl << endl;

    Info<< nl;
    runTime.printExecutionTime(Info);

    Info<< "End\n" << endl;

    return 0;
}


// ************************************************************************* //
